Quantopian Algo

by: PrymeTyme, 8 years ago


Hi , i work on an trading algorithm on quantopian due to the latest tutorials from Harris

i currently struggle on the order entry part of my code:

  
    if curr_high < mean_high_curr:
        buy = True
        if curr_high > mean_high_curr and buy == True:
            if security not in open_orders:
                order(security, 100)
                buy = False
    else:
        buy = False
        
    print('Buy = ' + str(buy))      
      
    if curr_low > mean_low_curr:
        sell = True
        if curr_low < mean_low_curr and sell == True:
            if security not in open_orders:
                order(security, -100)
                sell = False
    else:
       sell = False
    
    print('Sell = ' + str(sell))  


it seems that the Booleans work just perfectly as seen on the logs:

2016-10-24 15:31  PRINT (213.59999999999999, 214.63999999999999)
2016-10-24 15:31  PRINT Buy = False
2016-10-24 15:31  PRINT Sell = True
2016-10-25 15:31  PRINT (213.11000000000001, 214.53)
2016-10-25 15:31  PRINT Buy = False
2016-10-25 15:31  PRINT Sell = True
2016-10-26 15:31  PRINT (212.75999999999999, 214.08000000000001)
2016-10-26 15:31  PRINT Buy = True
2016-10-26 15:31  PRINT Sell = True
2016-10-27 15:31  PRINT (214.47999999999999, 215.31999999999999)
2016-10-27 15:31  PRINT Buy = True
2016-10-27 15:31  PRINT Sell = True
2016-10-28 15:31  PRINT (213.97999999999999, 214.97999999999999)


but it wont open any orders , so i must miss something , maybe someone can help me out , ?
maybe the Boolean = False gets assigned before the backtester  opens  the order ?

thnx



You must be logged in to post. Please login or register an account.



You're first asking for one thing to be true, if it is, then buy is true, then you ask the opposite to be true to actually do the buy:

    if curr_high < mean_high_curr:
        buy = True
        if curr_high > mean_high_curr and buy == True:


There, you're asking if the current high is LESS than the mean high, buy is true.

Then, before you execute your order, you are requiring the current high to be GREATER than the mean high.

You do the same for selling.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.


Hey ,

thanks Harrison , the fallacy was that i compared the "current high" when instead i should have used the historical high...
still need some testing to tell if the output is what i was expecting it to be , but at least iam a step closer to resemble my strategy..

fixed it like so:

    if curr_high > mean_high_curr and hist_high[-2] < mean_high_curr:
        if security not in open_orders:
            order(security, 100)


thanks

-PrymeTyme 8 years ago
Last edited 8 years ago

You must be logged in to post. Please login or register an account.